I'm writing my own membership provider (actually just extending the built-in one) and MembershipProvider stays red with an error that it cannot be resolved, even though I've added System.Web.Security:
public sealed class MRCMembershipProvider : MembershipProvider
{
//code here
}
Anyone got any ideas why this would be happening?
Make sure that you have added reference to the System.Web.ApplicationServices.dll assembly which is where this class is defined as stated in the documentation:
Namespace: System.Web.Security
Assembly: System.Web.ApplicationServices (in System.Web.ApplicationServices.dll)
It works only when the namespace for the MVC application is present.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
namespace MvcApplication6
{
public sealed class MRCMembershipProvider : MembershipProvider
{
}
}
Related
When I create a new Razor page in Visual Studio 2017, the separated code behind file did not get created.
This is the screenshot of the problem highlighted.
We can see the Razor page called List.cshtml does not contain the code behind file. Contrast that with the default page about.cshtml, for example.
1 - Right click on "resturants", add class:
2 - in your case, call it List.cshtml.cs. This will create the code behind. It nows needs wiring up. Open the class that has been created.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
//Add the MVC usings
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
//TODO The namespace will be correct in your code
namespace app_name.Pages.resturants
{
//public class List
//TODO correct the model name and inherit PageModel
public List1Model : PageModel
{
public void OnGet()
{
}
}
}
3 - In List.cshtml:
#page
#model app_name.Pages.resturants.List1Model
#{
}
More information can be found here on modifying the code behind https://learn.microsoft.com/en-gb/aspnet/core/data/ef-rp/sort-filter-page?view=aspnetcore-5.0
I seem to understand that to optimize an app you need to add the following
to your app class
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace MyAppNamespace
{
public partial class App
{
}
}
Now if you have many Prism modules where do you add this line of code
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
Many thanks
You can place it anywhere, but typically you would include it in the App.xaml.cs. The "assembly" attribute will apply it to all pages in the project.
You would need the attribute in each project where you have XAML files. Some general rules:
You can place this on individual XAML based Views/Pages to Opt-In or Opt-Out of Xaml Compilation:
[XamlCompilation(XamlCompilationOptions.Compile)]
public class ViewA : ContentPage
{
}
[XamlCompilation(XamlCompilationOptions.Skip)]
public class ViewB : ContentPage
{
}
You can use it instead as an Assembly Attribute like you have shown which is what most people choose to do.
The important thing here is that you can only place this ONCE per project, and it is on a Project by Project basis. You can put it in any file you choose as that comes down to preference. Typically you see this in one of the following locations:
In Properties/AssemblyInfo.cs. Though most templates no longer include this file by default for SDK Style projects, many people (myself included) still prefer a central location to look for and add assembly level attributes
In App.xaml.cs like:
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace AwesomeApp
{
public partial class App : PrismApplication
{
}
}
In an implementation of IModule which resides in a separate project
[assembly: XamlCompilation(XamlCompilationOptions.Compile)]
namespace AwesomeApp.Auth
{
public class AuthModule : IModule
{
}
}
Hi am using the Glass mapper in combination with Sitecore MVC. I created model below.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Test
{
using Glass.Mapper.Sc.Configuration.Attributes;
[SitecoreType(AutoMap = true)]
public class GlassTestModel
{
public virtual string Title { get; set; }
}
}
this is my view
#inherits Glass.Mapper.Sc.Web.Mvc.GlassView<Test.GlassTestModel>
<div>
<h2>Hello</h2>
<h2>#Model.Title</h2>
</div>
I also tried this first line
#model Test.GlassTestModel
and this one
#inherits System.Web.Mvc.WebViewPage<Test.GlassTestModel>
I created a view rendering in Sitecore. configured the model to use above.
When I render the view the model fields don't get filled. When I test in a controller I use for other controller view like below:
ISitecoreContext ctx = new SitecoreContext();
var item = ctx.GetCurrentItem<Test.GlassTestModel>();
I do get the title field. Any ideas?
I migrated my solution to V4 of the Glass.Mapper package. This works. With V3 I can't get the automapping to work.
I have a route config file that I'm trying to route all URLs that follow the formula .com/{a page}/{a subpage}, to route to a specific page .com/Default/Page.aspx. My problem is that it does this for all the pages (i.e., .com/Account/Login.aspx. Is there a way to specify that I want it to route to that page only when a user types it into the address bar, possible only when they leave out the .aspx extension? This is what I have so far:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.AspNet.Membership.OpenAuth;
using System.Web.Routing;
using Microsoft.AspNet.FriendlyUrls;
namespace CouponsForGiving
{
public static class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.Ignore("{resource}.axd/{*pathInfo}");
routes.MapPageRoute("LearnMore", "LearnMore", "~/LearnMore.aspx");
routes.MapPageRoute("DefaultPage", "{nponame}", "~/Default/NPOPage.aspx");
routes.MapPageRoute("CampaignPage", "{nponame}/{campaignname}", "~/Default/CampaignPage.aspx"); //This one routes a lot of other pages
routes.EnableFriendlyUrls();
}
}
}
Thanks!
Issue here is with the overriding of a route. If there are 2 routes with same number of parameters and if there is no hard-coded value, it will always consider the first route, which is declared. For Example, if following 2 routes are registered,
routeCollection.MapPageRoute("LearnMore", "{param1}/{param2}", "~/About.aspx");
routeCollection.MapPageRoute("DefaultPage", "{param3}/{param4}", "~/Account/Login.aspx");
In the above case, the route LearnMore will only be consider as valid which will be requesting About.aspx page.
You can do something like below:
routeCollection.MapPageRoute("LearnMore", "learnmore/{param1}/{param2}", "~/About.aspx");
routeCollection.MapPageRoute("DefaultPage", "default/{param3}/{param4}", "~/Account/Login.aspx");
This will redirect to the respective pages. You can go through below URL for more details on URL Routing.
http://karmic-development.blogspot.in/2013/10/url-routing-in-aspnet-web-forms-part-2.html
Thanks & Regards,
Munjal
Just wondering why I get compile time error :
"Attribute 'DisplayColumn' is not valid on this declaration type. It is only valid on 'class' declarations."
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace MyApplication.Models.DataAnnotations
{
[MetadataType(typeof(AppUser_DataAnnotations))]
public partial class AppUser
{
}
public class AppUser_DataAnnotations
{
[DisplayColumn("Name")]
public string FirstName { get; set; }
}
}
I'm using above to override mvccontrib rendered grid column headers. Any idea why I get compile time error? Any help would be greatly appreciated.
For people who run into this problem in the future maybe this can help:
I got the same problem as described above. As described in other answers it is important to use the DisplayName property and to include the System.ComponentModel namespace. Besides that, the property must have a getter (and setter) to get the attribute working. The errormessage is a bit confusing on this one.
The reason you are getting a compile-time error is because the [DisplayColumn] attribute can only be applied at the class level and not at a property of the class. You are probably confusing this attribute with [DisplayName].
You can also run into this problem when you decorate a Model Property with the attribute.
You need to decorate Controller Method's with ActionFilterAttribute's not property's.