Circular references on every page when opening project on another computer - c#

In order to work on my website on a second computer, I put the project on an usb key and opened it.
The initial project is building correctly, but whenever I try to open it on the second machine, I have a circular reference issue on every single page and can't figure out why.
For each aspx page, I've got:
Circular file references are not allowed. MyPage.aspx. Line 1.
For instance, here's the first line of "Profile.aspx":
<%# Page Title="" Language="C#" MasterPageFile="~/Game/Site.master" AutoEventWireup="true" CodeFile="Profile.aspx.cs" Inherits="Profile" %>
Site.master is actually in the same folder "Game" as all the other pages, and moving this master page in another folder seems to do the trick. However, this doesn't make sens since this is working correctly elsewhere...
Another odd thing: If I keep the project on the usb key (not working if I move the folder) and comment those lines, there is no circular references anymore:
public static class Database
{
private static string conxString = "";
static Database()
{
/*System.IO.StreamReader dataBaseFile = new System.IO.StreamReader("~/Files/DataBase.txt");
conxString = dataBaseFile.ReadToEnd();
dataBaseFile.Close();*/
}
}
Where database.txt contains the local database connection string.
If anyone has any idea please feel free, I really don't know how to address this matter.

Related

ASP.NET Getting compiler error message intermittently

I have an aspx page using only inline C# without a codebehind.
Running from Visual Studio it works, however adding the aspx file to the wwwroot of my local machine gives the message
Compiler Error Message: CS1513: } expected
If I rearrange the code to have the method above the code the message is instead
CS1519: Invalid token 'try' in class, struct, or interface member declaration
I expect it is something to do with server configuration, though I don't really know where to start.
The issue only occurs if there is methods, removing method1 from the below results in correct running.
This is the minimum entire file I was able to cause the error with
html
<%# Page Language="C#" %>
<%
try
{
string message = "Text";
Response.Write(method1(message));
}
catch
{
Response.Write("Err");
}
string method1(string source)
{
return source;
}
%>
If you're embedding code directly on the aspx page, that code still has to go in a method. Ex:
<%# Page Language="C#" %>
<%
void Page_Load(Object sender, EventArgs e)
{
try
{
string message = "Text";
Response.Write(method1(message));
}
catch
{
Response.Write("Err");
}
}
string method1(string source)
{
return source;
}
%>
By the way - we don't typically put C# code directly in the .aspx file. That's what the code behind system is for.
And we don't typically write directly to the response. It's hard to control where the markup will end up. In Web Forms, it's better to declare a control on the page and then add markup to that (or show/hide controls). Of course if we're going to talk about doing things well - then don't use Web Forms in the first place. It's a dead technology.
I have messed around with the Visual Studio project, running on an earlier version of .NET/C# yields the following error, It seems possible that this is the actual problem I have had
Error CS8059 Feature 'local functions' is not available in C# 6. Please use language version 7.0 or greater.
I am unsure why it thinks method1 is a local function and details are hard to come by.
Edit: To solve my problem I put the method in script tags instead of embedded code blocks. The methods then could be used from the embedded blocks and the script tag.
<script runat="server">
string method1(string source)
{
return source;
}
<script>

Why does any reference to Server.MapPath() kill my HttpContext Request.Params[]?

I am very much a novice in HttpHandlers. This is actually my first attempt at it.
I have this Ajax handler that responds to a jQuery ajax call in my web app front end:
public class ajaxMeetingHandler : IHttpHandler {
public void ProcessRequest(HttpContext context) {
string resultsJSON = "";
string requestType = context.Request.Params["requestType"];
if (!String.IsNullOrEmpty(requestType)) {
switch (requestType) {
case "RecentMXMeetings":
resultsJSON = SerialiseRecentMeetings(context, "Maintenance");
// SerialiseRecentMeetings() is a method in the class
// that works fine and is not included for brevity.
break;
// more cases (not included for brevity)
}
}
public bool IsReusable {
get {
return false;
}
}
}
}
And this works perfectly.
However, if I add either of these two statements anywhere in the code:
var x = context.Server.MapPath("/");
var y = HttpContext.Current.Server.MapPath("/");
...my Context.Request.Params[] collection becomes null, and IsNullOrEmpty(requestType) now sees requestType as null. In fact, ALL the Request.Params[] are null.
If I comment out those statements (and completely rebuild the solution) the thing goes back to working properly.
In the meantime, I am going to move the calls to MapPath() out to a static "RunTimeEnvironment" class so I can get the path I need from there without touching MapPath() from inside this HttpHandler. Is that a viable or recommended solution?
It turns out my problem was not related to the code itself, per se, but how I was running the project.
Visual Studio, when you click on the "Start Debug" button will start the solution at it's root document (ie, index.html). That is UNLESS the current open document is of a runnable type, such as .html. If your current open window is one of your class files (ie, .cs), it will not attempt to run the class file, but will start the debug session at your root document.
However, it WILL attempt to run a Generic Handler (.ashx) all by itself if that is the document you currently have open. And, by doing so, it was not starting at the index.html page which issues my ajax calls and sends parameters to the Handler. So, my Params collection was null because it was literally null. Running the .ashx by itself supplies no parameters.
So, the reason it worked after changing my call type from GET to POST and Back to GET again is because in doing so, I opened the index.html file to make that change, and when I started my debug session again, my current document was the index.html file, not the Generic Handler .ashx file.
I should probably lose a hundred reputations points just for making this dumb of a mistake. But in case it helps others, there it is.

Compilation Error - already defines a member

I've search for a solution for this issue but couldn't find one specific to my scenario.
When i update my test website to try out new changes, I seem to randomly (but frequently) get this compilation error.
CS0111: Type 'Views_warrantyNotification' already defines a member
called 'Page_Load' with the same parameter types
Now on searching for a solution, it all points to having another Page_Load() but i can assure you, there isn't one on the page. I do have an override in the base page, so at the top of the .cs i have ....
public partial class Views_warrantyNotification : CustomBase
{
...
}
then in CustomBase.cs i have...
protected override void OnLoad(EventArgs e)
{
if (!IsPostBack && Directory.Exists(Server.MapPath("~/UploadFiles/") + Session.SessionID)) //if the directory is there on page load then it's come from another form. Delete it!
Directory.Delete(Server.MapPath("~/UploadFiles/") + Session.SessionID, true);
base.OnLoad(e);
}
now this has never been a problem before and I've had this code in place for about 18 months. So I'm struggling to understand why this would suddenly start causing an issue, as such, I'm confused as to why I keep getting this error (randomly).
I've tried recycling the app pool and restarting the website after uploading the updated website files, but this doesn't seem to work.
What I also find strange, is that if I close my browser window and navigate back to the page I'm testing, it will load just fine.
Any idea's would be most appreciated, this is really annoying and it's slowing down my production :(
Thanks

Why won't my ascx file pick up my code behind properties?

My web app is a solution built on top of another solution. The base solution is meant to be a platform for multiple products. For the most part, this works fine, but weird things happen when I create product specific views.
I am using ViewUserControl<SomeViewModel> for my code behind class. In my code behind, I have access to this.Model and all the other goodies I'd expect from this class. But in my ascx file, I get red squiggley lines when I try to access this.Model or other properties defined in ViewUserControl. I also get red squiggley lines when I try to access properties defined directly in my code behind.
What's more interesting is, I don't get any real errors from this. The view renders just fine at run time and does not give me any build errors. But my ascx file thinks there will be errors. If I create the exact same view in the platform namespaces, it works fine. No red squiggles.
I find this to be really annoying. It's not a show stopper by any means, but if I'm going to be using an IDE with intellisense and all that jazz, I'd sure like it to work properly, and pick up the properties that are supposed to be there.
Has anyone else run into this? Do you know of a way to fix this?
Thanks!
Edit
It was requested that I post some code. Here's the code behind:
namespace MyProject.MyProduct.Web.Views
{
public class EditSearch : ViewUserControl<SearchResultsViewModel>
{
public bool IsSearchTypeA()
{
...............
}
public bool IsSearchTypeB()
{
...............
}
}
}
And here's my ascx:
<%
if (!this.IsSearchTypeB())
{
string categoryPageTitle = this.Model.SearchWidgetParameters.Search.CategoryPageTitle;
string categoryPageUrl = this.Model.SearchWidgetParameters.Search.Filters.CategoryPageUrl;
if (!string.IsNullOrEmpty(categoryPageUrl))
{
%> <div id="coid_website_backtoCategoryPageLink"> <%
string tocGuid = this.Model.SearchWidgetParameters.Search.Filters.TocGuid;
if (!string.IsNullOrEmpty(tocGuid))
{
categoryPageUrl += "?guid=" + tocGuid;
}
var backToLink = new HyperLink();
if (this.IsSearchTypeA())
{
backToLink.Text = "Edit Search";
}
else
{
backToLink.Text = "Back to " + TranslatedHtmlTextWriter.Translate(categoryPageTitle);
}
backToLink.NavigateUrl = TransactionOperations.AddContextToUrl(categoryPageUrl.StartsWith("/Browse/") ? categoryPageUrl : "/Browse/" + categoryPageUrl,
WebsiteTransitionType.Default, // Requested: CategoryPage
TransactionOperations.DefaultContextData);
backToLink.RenderControl(this.Writer);
%>
</div>
<%
}
}
%>
Edit
For those of you who are telling me that ASP.NET MVC cannot or does not use code behind, I'm sorry but this is horse hockey. This project has existed for years and there is a widely used product that runs on it. My product is only just recently jumping onto the Platform. The Platform solution uses code behind all over the place, and it works fine. In fact, it works fine at runtime in my product's solution as well, I just have the problem that my ascx file doesn't seem to know about my code behind. Furthermore, ViewUserControl is a System.Web.MVC class. Are you still going to tell me that code behind isn't used in ASP.NET MVC?
Since you are developing MVC you cannot use code behind. Instead, what do you think about adding this at the top of your .acsx file:
<%# Import Namespace="Namespace.Model" %>
Then you can access everything you have in there without so much complication.
ASP.NET MVC does not use code behind. It sounds like you are mixing ASP.NET MVC and ASP.NET WebForm pages.
I suggest you take a look at http://www.asp.net/mvc. It has some great tutorials on getting started with MVC and how it works.

Silverlight C# - ComponentOne Spellchecker not loading dictionary

This may be a long shot, but I'm using ComponentOne's Spellchecker control for Silverlight. I made a test project, added a plain textbox and a button to it, added the references to the C1.Silverlight and C1.Silverlight.SpellChecker bits, and added the dictionary file to my project.
In the code, I called up the spellchecker on button1's click event and it worked SPLENDIDLY. The spellchecker dialog shows up, and works exactly as it should.
Since that test was successful, I then tried to implement this into my existing project. I've had no success for absolutely NO reason that I can determine, since I used the EXACT SAME code.
Here's the code I use to call the component:
using C1.Silverlight;
using C1.Silverlight.SpellChecker;
using C1.Silverlight.Resources;
public partial class MainPage : UserControl
{
C1SpellChecker spellChecker = new C1SpellChecker();
public MainPage()
{
InitializeComponent();
spellChecker.MainDictionary.LoadAsync("C1Spell_en-US.dct");
}
private void btnSpelling_Click(object sender, RoutedEventArgs e)
{
var dlg = new C1SpellDialog();
spellChecker.CheckControlAsync(txtArticle, false, dlg);
}
The references to C1.Silverlight and C1.Silverlight.Spellchecker are added to this project as well, and the dictionary as been added in the same fashion as well. The issue seems to be that for whatever reason the dictionary is not loading, because the spellChecker.Enabled method returns whether or not the main dictionary has been loaded. If I call MessageBox.Show("SpellChecker Enabled = " + spellChecker.Enabled.ToString()); it shows false, even though the call to load the dictionary is there (as you can see).
What would cause the dictionary to not load? Have I added it to my project incorrectly somehow?
EDIT: I suspect that I have added the dictionary to the project incorrectly, because the ComponentOne reference states:
If C1SpellChecker cannot find the
spelling dictionary, it will not throw
any exceptions. The Enabled property
will be set to false and the component
will not be able to spell-check any
text.
I just don't know what's wrong though because it was added in the same way that it was in the test project (Right clicked on the project.web->Add->Existing Item)
As always, thank you!
-Sootah
You could add the dictionary to the Silverlight app as an embedded resource and then load it using this code:
public MainPage()
{
InitializeComponent();
// load C1SpellChecker dictionary from embedded resource
var asm = this.GetType().Assembly;
foreach (var res in asm.GetManifestResourceNames())
{
if (res.EndsWith(".dct"))
{
using (var s = asm.GetManifestResourceStream(res))
{
sc.MainDictionary.Load(s);
break;
}
}
}
}
I think this post is duplicated in our forum as well, but will answer first here. Please try this:
1) Try to access the .dct file using your browser. If you cannot see it, it's probably because your web server is not serving that type of files. You need ton configure the web server to allow it.
2) verify the URL you are using is correct.http://helpcentral.componentone.com/CS/silverlight_161/f/78/p/86955/241328.aspx#241328
3) Check you are setting everything correctly: http://helpcentral.componentone.com/CS/silverlight_161/f/78/p/81924/227790.aspx#227790
Hope this helps!

Categories