相关疑难解决方法(0)

"命名空间ASP中不存在ASP.global_asax"

我在App_Code上创建了一个RazorFunctions.cshtml文件

@functions {
    public static string GetActiveClassIf(string controllerName, string actionName = null)
    {
        var routeData = @HttpContext.Current.Request.RequestContext.RouteData;
        string currentController = routeData.Values["controller"].ToString();
        string currentAction = routeData.Values["action"].ToString();
        return controllerName == currentController &&
            (String.IsNullOrEmpty(actionName) || currentAction == actionName) ? "active" : "";
    }
}
Run Code Online (Sandbox Code Playgroud)

当我编译时,它给我2个错误(编译获得成功和站点工作没有问题)但错误很烦人.

RazorFunctions.cshtml作为内容(尝试编译但当然不能与cshtml文件一起使用)

Global.asax.cs是:

public class MvcApplication : System.Web.HttpApplication
{
    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        ModelMetadataConfig.RegisterModelMetadata();
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
        Database.SetInitializer(new MigrateDatabaseToLatestVersion<ApplicationDbContext, Configuration>());
        //Database.SetInitializer(new DropCreateDatabaseAlways<ApplicationDbContext>());
    }
}
Run Code Online (Sandbox Code Playgroud)

<%@ Application Codebehind="Global.asax.cs" Inherits="Bouron.Web.MvcApplication" Language="C#" %>
Run Code Online (Sandbox Code Playgroud)

这是我第一次使用App_Code,所以我不知道还能做什么,所有搜索返回ASP.NET 1-2的结果,是剃刀甚至不存在的过时所以我不知道怎么可以我解决了这个问题

我正在使用Visual Studio 2015(以防万一)

c# asp.net asp.net-mvc razor

52
推荐指数
3
解决办法
3万
查看次数

如何从Global.asax获取OwinContext?

我正在尝试设置我的依赖注入,我需要IAuthenticationManager从ASP.NET身份注入一个OwinContext.

为此,我来自我的Global.asax -> ServiceConfig.Configure()跑步:

 container.Register(() => HttpContext.Current.GetOwinContext().Authentication);
Run Code Online (Sandbox Code Playgroud)

但是,当我运行我的应用程序时,我收到此消息:

在上下文中找不到owin.Environment项

为什么这个HttpContext.Current.GetOwinContext()不能从Global.asax获得?

Startup.cs

[assembly: OwinStartupAttribute(typeof(MyApp.Web.Startup))]
namespace Speedop.Web
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Startup.Auth.cs

public partial class Startup
{
    public void ConfigureAuth(IAppBuilder app)
    {
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            Provider = new CookieAuthenticationProvider
            {
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<UserManager<User, int>, User, int>(
                    validateInterval: TimeSpan.FromMinutes(30),
                    regenerateIdentityCallback: (manager, user) => manager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie),
                    getUserIdCallback: (id) => (Int32.Parse(id.GetUserId())) …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc simple-injector owin

16
推荐指数
1
解决办法
7276
查看次数

在没有MVC的纯ASP.NET Web API服务中,我们是否还需要Global.asax中的AreaRegistration.RegisterAllAreas()

我试图创建一个干净的ASP.NET Web API服务,如果可能的话,不引用MVC程序集.我关注了这个博客http://www.codeproject.com/Articles/615805/Creating-a-Clean-Minimal-Footprint-ASP-NET-WebAPI 但是在Global.asax中使用这一行我还是要导入System.Web. Mvc组装.如果我将其删除,会对我的网络API服务产生影响吗?我尝试在没有它的情况下在我的本地运行我的服务,我没有遇到任何错误.

protected void Application_Start()
{
        //AreaRegistration.RegisterAllAreas(); do we still need this?

        WebApiConfig.Register(GlobalConfiguration.Configuration);  
        HandlerConfig.RegisterGlobalHandlers(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalConfiguration.Configuration.Filters);            

}
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc-4 asp.net-web-api

11
推荐指数
1
解决办法
9055
查看次数

OwinStartupAttribute不应该在global.asax和Application_Start之前运行吗?

我需要运行的应用程序开始之前的代码和到现在为止我已经使用WebActivator要做到这一点,但如果我理解正确的OwinStartupAttribute是更适合于这一点,但对我来说,问题是,它运行后Application_StartGlobal.asax,这是正确的或我可以配置它运行预应用程序启动?

c# asp.net-mvc owin asp.net-mvc-5

5
推荐指数
1
解决办法
6634
查看次数

Starts..c中的Global.asax Application_Error等价物

我试图在将.NET应用程序写入事件日志之前捕获错误.我已经在接受这个问题的答案中看到,这样做的方法是在Global.asax中包含一个Application_Error(或Application_OnError它说的)函数.

但是,我们现在只切换到使用Startup.cs,并且无法确定如何进行等效调用.这个问题的公认答案表明这可能是不可能的.有没有人确切知道是否有相同的方法来处理这些错误?

c# asp.net error-handling startup event-log

4
推荐指数
1
解决办法
1937
查看次数