在MVC数据库权限与NHibernate [英] Database permissions in MVC with NHibernate

查看:125
本文介绍了在MVC数据库权限与NHibernate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在企业内部网的MVC Web应用程序,使用功能NHibernate。

I'm working on an intranet MVC web application, using Fluent NHibernate.

众所周知,建立必要的 ISessionFactory 是沉重的,因此应做一次。因此,我在的Application_Start 在Global.asax文件中创建它,然后它缓存以备将来使用应用程序。

As everyone knows, creating the necessary ISessionFactory is heavy, and therefore should be done only once. Hence, I create it in the Global.asax file during Application_Start, then cache it in the application for future use.

问题是,我只是想给访问谁已经有对数据库权限的用户。

The problem is that I only want to give access to users who already have permissions over the database.

这可能的理论上的由连接字符串中(而不是通过提供一个SQL的用户名和密码)定义集成安全性= SSPI 解决。

This could theoretically be solved by defining Integrated Security=SSPI in the connection string (rather than by providing an SQL username and password).

不过,这期间 Fluently.Configure 引发错误,因为在的Application_Start 时的配置,正在通过托管应用程序,它没有权限来连接到数据库的进程中运行。

However, this raises an error during Fluently.Configure, because the configuration occurs during Application_Start, which is being run by the process hosting the application, which does not have permissions to connect to the DB.

我要如何解决这个问题?

How do I solve this issue?

推荐答案

您可以初始化它在的BeginRequest 而不是的Application_Start

You could initialize it in BeginRequest instead of Application_Start:

private static bool _initialized = false;
private static object _syncRoot = new object();

protected void Application_BeginRequest(object source, EventArgs e)
{
    if (_initialized)
    {
        return;
    }

    lock (_initialized)
    {
        if (_initialized)
        {
            return;
        }

        // Initialize the session factory here and cache it

        _initialized = true;
    }
}

这篇关于在MVC数据库权限与NHibernate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆