答案 0 :(得分:1)
你不应该这样做。
不应在运行时根据会话更改webconfig。记住每个用户都有他/她自己的会话。这意味着如果同时存在多个用户,则可能存在并发问题,例如,您可以在配置中使用user1的用户名和user2的密码。
您可以做的是在视图中使用以下内容:
@Html.MvcReportViewer(string reportPath, string reportServerUrl = null, string username = null, string password = null, IEnumerable> reportParameters = null, ControlSettings controlSettings = null, object htmlAttributes = null, FormMethod method = FormMethod.Get)
其中用户名和密码来自您的Viewbag。