Controllers & ViewComponents
Smartstore modules are pure MVC projects. This means that normal controller classes can be implemented using the MVC pattern. Since varying fields of application often require repetitive tasks, we have created base controllers following the DRY principle. These take care of many tasks and can of course be used to implement your own controllers.
The base controllers are located in the Controllers directory of the Smartstore.Web.Common project. By including the most important attributes and implementing auxiliary methods, they keep controllers consistent and eliminate redundancy.
SmartController
The SmartController is the base controller that all other controllers implement. The provided functionality and members are therefore present in all controllers. Since the SmartController is the lowest possible abstraction, it should not be used directly. It is better to use controllers that implement the SmartController as a base for your own controller, such as the PublicController or the AdminController.
Members
Methods
ManageController
The ManageController provides auxiliary methods, that can be used to configure domain entities and settings. Since this is mostly used in the admin area, we recommend basing your controller on the AdminController instead of the ManageController directly. It implements the ManageController and adds more auxiliary methods relevant to the admin area.
Methods
AdminController
The AdminController adds the following attributes:
Area("Admin")
Specifies Admin as area of the controller.
AutoValidateAntiforgeryToken
An attribute that causes antiforgery token validation for all insecure HTTP methods. An antiforgery token is required for HTTP methods other than GET, HEAD, OPTIONS, and TRACE.
AuthorizeAdmin
Checks whether the current user has permission to access the administration backend.
ValidateAdminIpAddress
Verifies that the IP address being used matches one of the addresses defined in AdminAreaAllowedIpAddresses from the SecuritySettings.
PublicController
The PublicController implements the SmartController and adds the following attributes:
CookieConsent
Checks if the visitor has already allowed the use of cookies and opens the CookieManager if not.
PreviewMode
Enables the use of preview mode in the public store as long as preview mode is enabled in the backend.
CheckStoreClosed
Checks if the store has been closed by the admin and returns a redirect result to the StoreClosed action.
AuthorizeShopAccess
Checks whether the current user has permission to access the shop.
TrackActivity(Order = 100)
Saves current user activity information including the date, IP address and the visited page, in the database.
CheckAffiliate(Order = 100)
Checks if a visiting customer was referred to the shop by an affiliate by analyzing the request query.
SaveChanges(
typeof(SmartDbContext),
Order = int.MaxValue)
Saves all pending changes in a DbContext instance to the database after an action method has been executed.
ViewComponents
ViewComponents is a feature that was added to ASP.NET Core. They provide developers with the means to create recurring components that are used in the application GUI. Similar to controllers, the SmartViewComponent base class adds ways to perform repetitive tasks and some auxiliary methods.
Members
Methods
Events
Last updated
Was this helpful?