私はこのファイルを持っています:C:¥Documents and Settings¥extryasam¥My Documents¥Visual Studio 2010¥Projects¥FCR¥WebApplication4¥config¥roles.txtこれをC#アプリケーションにインポートします。私は完全なパスを挿入しても問題ありませんが、私はウェブサイトと同様のやり方をしたいと思っています。 "\ config \ roles.txt"C#パスの問題
ただし、以下のコードでは動作しません。
これは私のコードです:
public string authenticate()
{
WindowsIdentity curIdentity = WindowsIdentity.GetCurrent();
WindowsPrincipal myPrincipal = new WindowsPrincipal(curIdentity);
//String role = "NT\\Internet Users";
//string filePath = Server.MapPath("config/roles.txt");
//string filePath = (@"~/WebApplication4/config/roles.txt");
//string filePath = Path.GetDirectoryName(@"\config\roles.txt");
string filePath = Path.GetPathRoot(@"/config/roles.txt");
string line;
string role = "";
if (File.Exists(filePath))
{
StreamReader file = null;
try
{
file = new StreamReader(filePath);
while ((line = file.ReadLine()) != null)
{
role = line;
}
}
finally
{
if (file != null)
{
file.Close();
}
}
}
if (!myPrincipal.IsInRole(@role))
{
return "401.aspx";
}
else
{
return "#";
}
}
それはどうやって間違っていますか? – Jodrell
WinFormsやConsoleアプリケーションからWebアプリケーションのファイルにアクセスしたいのですか? –
投稿にはタグが付いたASP.NETがあるので、ファイルがASP.NETのサーバー側にアクセスしていると思います –