asp.net-mvc

Redirecting to a custom route in MVC

怎甘沉沦 提交于 2021-02-11 08:06:42
问题 I have setup a custom route in my MVC site. I am having trouble figuring out how to redirect to it though. Here is my custom route code: public class MemberUrlConstraint : IRouteConstraint { public bool Match(HttpContextBase httpContext, Route route, string parameterName, RouteValueDictionary values, RouteDirection routeDirection) { if (values[parameterName] != null) { var permalink = values[parameterName].ToString(); return string.Equals(permalink, Member.GetAuthenticatedMembersUrl(),

How to cast UserStore<IdentityUser> to its base class IUserStore<IUser>?

寵の児 提交于 2021-02-11 07:10:37
问题 I am trying to use the new asp.net identity provider with my abstraction layer of my models domain, wich have a implementation of Entity Framework, so I would like to use the out of box version of identity with entity framework in my data access layer. How can I convert an UserStore<IdentityUser> to its base interface IUserStore<IUser> Once UserStore is an implementation of IUserStore, I can get the cast by this: UserStore<IdentityUser> as IUserStore<IdentityUser> But I want to avoid the

Assign IENumerable<int> to a hiddenfor

Deadly 提交于 2021-02-11 06:11:51
问题 I am working with a project where in I have a veiwmodel [Required(ErrorMessage = "Enter Title")] [Display(Name="Title")] public string Title { get; set; } [Required(ErrorMessage = "Enter Description")] [Display(Name="Description")] public string Description { get; set; } [Required(ErrorMessage = "Select Site")] [Display(Name = "Site")] public string Site { get; set; } [Required(ErrorMessage = "Upload File is required")] [Display(Name = "Upload File")] [ValidatePlanFile] public

File Upload in ASP.NET MVC 5

限于喜欢 提交于 2021-02-11 05:57:20
问题 I am unable to upload file in folder. I am not able to find the mistake. The UploadFile View returns on same view after uploading file. Model Class: public class Upload { public int UploadId { get; set; } public string UploadTitle { get; set; } public string UploadURL { get; set; } } Here is the Controller(FileUpload) Action: public ActionResult UploadFile(HttpPostedFileBase file, Upload upload) { if (ModelState.IsValid) { if (file != null) { string fil = System.IO.Path.GetFileName(file

Manual outputcache refresh

一曲冷凌霜 提交于 2021-02-11 00:32:21
问题 Right now I have OutCache on an action with duration set to 365 days. However depending on some events I would like to clear the cache and there are multiple conditions for clearing cache. Moreover, VaryByParam is not an option. How can I achieve this? I think I can do something like this, store a variable in cookie like: RefreshCache = false and check this in VaryByCustom override method. Incase the RefreshCache evaluates to true, reset it to false, increment VaryByCustom argument variable

Manual outputcache refresh

℡╲_俬逩灬. 提交于 2021-02-11 00:31:11
问题 Right now I have OutCache on an action with duration set to 365 days. However depending on some events I would like to clear the cache and there are multiple conditions for clearing cache. Moreover, VaryByParam is not an option. How can I achieve this? I think I can do something like this, store a variable in cookie like: RefreshCache = false and check this in VaryByCustom override method. Incase the RefreshCache evaluates to true, reset it to false, increment VaryByCustom argument variable

ASP.NET: Get correct url to uploaded image

时间秒杀一切 提交于 2021-02-10 23:52:53
问题 I upload images like this: private const string ProfilePicturesUploadDir = "~/_useruploads/ProfilePictures/"; var fileName = System.Guid.NewGuid()+Path.GetExtension(file.FileName); file.SaveAs(Path.Combine(HttpContext.Current.Server.MapPath(ProfilePicturesUploadDir), fileName)); I want to retrieve the correct image in my view code. I am trying this: public static string GetProfilePictureUrl(string profilePicture) { return HttpContext.Current.Server.MapPath(ProfilePicturesUploadDir +

ASP.NET: Get correct url to uploaded image

青春壹個敷衍的年華 提交于 2021-02-10 23:48:41
问题 I upload images like this: private const string ProfilePicturesUploadDir = "~/_useruploads/ProfilePictures/"; var fileName = System.Guid.NewGuid()+Path.GetExtension(file.FileName); file.SaveAs(Path.Combine(HttpContext.Current.Server.MapPath(ProfilePicturesUploadDir), fileName)); I want to retrieve the correct image in my view code. I am trying this: public static string GetProfilePictureUrl(string profilePicture) { return HttpContext.Current.Server.MapPath(ProfilePicturesUploadDir +

ASP.NET: Get correct url to uploaded image

情到浓时终转凉″ 提交于 2021-02-10 23:47:03
问题 I upload images like this: private const string ProfilePicturesUploadDir = "~/_useruploads/ProfilePictures/"; var fileName = System.Guid.NewGuid()+Path.GetExtension(file.FileName); file.SaveAs(Path.Combine(HttpContext.Current.Server.MapPath(ProfilePicturesUploadDir), fileName)); I want to retrieve the correct image in my view code. I am trying this: public static string GetProfilePictureUrl(string profilePicture) { return HttpContext.Current.Server.MapPath(ProfilePicturesUploadDir +

Open Specified ASP.NET MVC Views From Hyperlinks Inside Email Body

我们两清 提交于 2021-02-10 22:22:41
问题 I just learn about ASP.NET MVC. I hava a website with this following scenario: Login -> Main Page (Index) -> Edit Page (Edit) So, In LoginController when user login, it will redirect to main page and edit a record from MainPage . Everytime a new record is created through ASP.NET MVC, the system will send an email to manager. Within email message, there is a hyperlink that will redirect the manager to edit form. But first, he needs to login because the edit form cant be opened unless he login.