小编Owe*_*ing的帖子

使用 HttpHandler 继续处理页面以保护子文件夹

我创建了一个 HttpHandler 来检查特定目录中的用户授权。它正在运行并经过测试,但是,在运行 ProcessRequest 方法后,它似乎不会继续处理页面。这是它的基础知识:

public AdminProtectionHandler() { }

bool IHttpHandler.IsReusable { get { return true; } }    

void IHttpHandler.ProcessRequest(HttpContext context) {
    if (!Sessions.CurrentUser.Authenticated)
    {
        context.Response.Write("ACCESS DENIED");
        context.Response.End();
    }
}
Run Code Online (Sandbox Code Playgroud)

在子文件夹的 web.Config 中:

<httpHandlers>
    <add verb="*" path="*" validate="true" type="AdminProtectionHandler" />        
</httpHandlers>
Run Code Online (Sandbox Code Playgroud)

未通过身份验证时,我会按预期得到响应:ACCESS DENIED

通过身份验证后,我得到一个空白页,就好像请求刚刚停止一样。

c# asp.net httphandler

2
推荐指数
1
解决办法
1413
查看次数

ASP.NET Core .css扩展进入控制器

我将ASP.NET应用程序迁移到ASP.NET Core。

http:// localhost:56623 / js / jquery.js

工作正常,但

http:// localhost:56623 / css / bootstrap.css

调用我的CategoryController的CheckIsCustomPage操作,因此我的应用程序当然会引发异常。

我能做什么?

app.UseMvc(routes =>
{
    routes.MapRoute(
        name: "Category",
        template: "{sefLink}/{pageNumber}",
        defaults: new { controller = "Category", action = "CheckIsCustomPage", pageNumber = "1" }
    );

    routes.MapRoute(
        name: "Ajax",
        template: "ajax/{action}",
        defaults: new { controller = "Ajax" });

    routes.MapRoute(
        name: "default",
        template: "{controller=Home}/{action=Index}/{id?}");
});
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc asp.net-core

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

为什么我必须使用Dispose()?

这是我的代码:

public void InsertData()
{
    using (SqlConnection connection = new SqlConnection(DBHelper.ConnectionString))
    {
        using (SqlCommand command = new SqlCommand("Some Simple Insert Query", connection))
        {
            connection.Open();
            command.ExecuteNonQuery();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但是我找到了这个代码示例:

public void InsertData()
{
    SqlConnection connection = new SqlConnection(DBHelper.ConnectionString);
    connection.Open();
    SqlCommand command = new SqlCommand("Some Simple Insert Query", connection);
    command.ExecuteNonQuery();

    command.Dispose();
    connection.Close();
    connection.Dispose();
}
Run Code Online (Sandbox Code Playgroud)

为什么作者使用

command.Dispose()

connection.Dispose();

在他们的代码?

c# ado.net dispose

0
推荐指数
1
解决办法
604
查看次数

performSegue(withIdentifier .......)无效

长话短说,我的segue无法执行到我已创建的下一个控制器.很多帮助将不胜感激.

    override func viewDidLoad() {
        super.viewDidLoad()


        var returnValue: Int = UserDefaults.standard.integer(forKey: "quiz1Validation")
        if (returnValue == 1)
        {
            performSegue(withIdentifier: "completed", sender: self)
        }
        else {
        var returnValue: Int = UserDefaults.standard.integer(forKey: "userScore")
        scorelabel.text = "Score:\(returnValue)"
        RandomQuestions()
    }

}
Run Code Online (Sandbox Code Playgroud)

ios segue swift

0
推荐指数
1
解决办法
901
查看次数

标签 统计

c# ×3

ado.net ×1

asp.net ×1

asp.net-core ×1

asp.net-mvc ×1

dispose ×1

httphandler ×1

ios ×1

segue ×1

swift ×1